/*
 * 2005-11-12 lxm 创建。 
 */
package com.hd123.rumba.catalog;

import java.text.ParseException;

import net.sf.hibernate.HibernateException;

import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.runtime.DBaseEntity;
import com.hd123.rumba.runtime.IPersistent;
import com.hd123.rumba.runtime.NamingMgr;

/**
 * @author lxm
 * 
 * ICatalog对应的数据交换对象
 * 
 */
public class DCatalog extends DBaseEntity {

  private String code;
  private String itemType;
  private int level1Length = 0;
  private int level2Length = 0;
  private int level3Length = 0;
  private int level4Length = 0;
  private String isMaster;
  private String name;

  // /////////////////////////
  // 用于 Web Service 数据交换

  /**
   * 从指定的接口对象赋值。
   * 
   * @param source
   */
  public void assignFrom(IPersistent source) {
    super.assignFrom(source);
    if (source instanceof ICatalog) {
      this.code = exportString(source, "getCode");
      this.itemType = exportString(source, "getItemType");
      try {
        this.level1Length = ((ICatalog) source).getLevel1Length();
      } catch (Exception e) {
      }
      try {
        this.level2Length = ((ICatalog) source).getLevel2Length();
      } catch (Exception e) {
      }
      try {
        this.level3Length = ((ICatalog) source).getLevel3Length();
      } catch (Exception e) {
      }
      try {
        this.level4Length = ((ICatalog) source).getLevel4Length();
      } catch (Exception e) {
      }
      this.isMaster = exportBoolean(source, "getIsMaster");
      this.name = exportString(source, "getName");
    }
  }

  /**
   * 将数据赋值给指定的接口对象。
   * 
   * @param source
   */
  public void assignTo(IPersistent target) throws ParseException, BusinessException,
      HibernateException {
    super.assignTo(target);
    if (target instanceof ICatalog) {
      importString(target, "setCode", this.code);
      importString(target, "setItemType", this.itemType);
      try {
        ((ICatalog) target).setLevel1Length(this.level1Length);
      } catch (Exception e) {
      }
      try {
        ((ICatalog) target).setLevel2Length(this.level2Length);
      } catch (Exception e) {
      }
      try {
        ((ICatalog) target).setLevel3Length(this.level3Length);
      } catch (Exception e) {
      }
      try {
        ((ICatalog) target).setLevel4Length(this.level4Length);
      } catch (Exception e) {
      }
      importBoolean(target, "setIsMaster", this.isMaster);
      importString(target, "setName", this.name);
    }
  }

  /**
   * 用于导入处理，根据Uuid导入指定的Catalog。
   * 
   * @param uuid
   * @return
   * @throws BusinessException
   * @throws HibernateException
   */
  public static ICatalog importCatalog(String uuid) throws BusinessException, HibernateException {
    if (uuid == null || uuid.equals(new String("")))
      return null;
    ICatalog catalog = ((ICatalogMgr) NamingMgr.getInstance().lookupMgr(ICatalogMgr.class))
        .getCatalog(uuid);
    if (catalog == null)
      throw new BusinessException("系统中不存在指定的目录(uuid=" + uuid + ")。");
    return catalog;
  }

  // /////////////////////////
  // 属性方法

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getIsMaster() {
    return isMaster;
  }

  public void setIsMaster(String isMaster) {
    this.isMaster = isMaster;
  }

  public String getItemType() {
    return itemType;
  }

  public void setItemType(String itemType) {
    this.itemType = itemType;
  }

  public int getLevel1Length() {
    return level1Length;
  }

  public void setLevel1Length(int level1Length) {
    this.level1Length = level1Length;
  }

  public int getLevel2Length() {
    return level2Length;
  }

  public void setLevel2Length(int level2Length) {
    this.level2Length = level2Length;
  }

  public int getLevel3Length() {
    return level3Length;
  }

  public void setLevel3Length(int level3Length) {
    this.level3Length = level3Length;
  }

  public int getLevel4Length() {
    return level4Length;
  }

  public void setLevel4Length(int level4Length) {
    this.level4Length = level4Length;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

}
